package com.feng.chat.ws;

import com.feng.chat.utils.JwtUtil;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.websocket.HandshakeResponse;
import javax.websocket.server.HandshakeRequest;
import javax.websocket.server.ServerEndpointConfig;
import java.util.List;
import java.util.Map;

public class GetHttpServletRequestConfigurator extends ServerEndpointConfig.Configurator {
    @Override
    public void modifyHandshake(ServerEndpointConfig sec, HandshakeRequest request, HandshakeResponse response) {

        Map<String, Object> userProperties = sec.getUserProperties();
        Map<String, List<String>> parameterMap = request.getParameterMap();
        List<String> token = parameterMap.get("token");
        Integer id = JwtUtil.parserToken(token.get(0));

        userProperties.put("id", id);


    }
}
